#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=2e4+5;
int n;
int a[N],b[N],w[N];
void Swap(int x,int y){
	swap(w[b[x]],w[b[y]]);
	swap(b[x],b[y]);
}
void Change(int l,int r,int x){
	int len=r-x; 
	for(int i=x;i>=l;i--){
		int now=i;
		for(int j=1;j<=len;j++){
			Swap(now,now+1);
			now++;
		}
	}
}
void Change(int l,int r,int x,vector<pair<int,int>>&ans){
	for(int i=1;i<=x-l+1;i++)ans.push_back({1,l});
	int len=r-x; 
	for(int i=x;i>=l;i--){
		int now=i;
		for(int j=1;j<=len;j++){
			Swap(now,now+1);
			now++;
		}
	}
}
bool check(int x){
	for(int i=1;i<=n;i++)
		b[i]=a[i];
	for(int i=1;i<=n;i++)
		w[b[i]]=i;
	for(int i=n;i>=x;i--){
		int now=w[i],R=n-i+1,len=R-now;
		while(len>=x-1){
			for(int j=1;j<x;j++)
				Swap(now,now+1),now++;
		}
		Change(n-x+1,n-i+1,now);
	}
	for(int i=1;i<=n;i++)
		if(b[i]!=i)return 0;
	return 1;
}
void Out(int x){
	for(int i=1;i<=n;i++)
		b[i]=a[i];
	for(int i=1;i<=n;i++)
		w[b[i]]=i;
	vector<pair<int,int>>ans;
	for(int i=n;i>=x;i--){
		int now=w[i],R=n-i+1,len=R-now;
		while(len>=x-1){
			ans.push_back({1,now});
			for(int j=1;j<x;j++)
				Swap(now,now+1),now++;
			len-=x-1;
		}
		Change(n-x+1,n-i+1,now,ans);
	}
	for(int i=x-1;i>1;i--){
		int now=w[i],R=n-i+1,len=R-now;
		while(len>0){
			ans.push_back({2,now}); 
			len--;
		}
	}
	return;
}
signed main(){
	freopen("rotate.in","r",stdin);
	freopen("rotate.out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]);
	int m=((int)sqrt(n))+1;
	for(int i=0;i<=min(m-2,10);i++){
		if(check(i)){
			Out(i);
			return flush(),0;
		}
	}
	Out(m);
	return flush(),0;
}

